﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;


namespace Scheduling.Models
{
    /// <summary>
    /// Model of a course instance
    /// </summary>
    public class CourseInstance
    {
        /// <summary>
        /// ID of the course instance provided by the administry.
        /// </summary>
        public int ID { get; set; }

        /// <summary>
        /// Course this instance belongs to. 
        /// </summary>
        public Course Course { get; set; }

        /// <summary>
        /// Period of the course 1-5.
        /// </summary>
        [Range(1, 5, ErrorMessage = "Period must be between 1 and 5")]
        public int? Period { get; set; }

        /// <summary>
        /// Year the course is taught.
        /// </summary>
        [Range(1970, 2038)]
        public int Year { get; set; }

        /// <summary>
        /// Boolean indicating if the it is a campuscourse or a distance course.
        /// </summary>
        public bool OnCampus { get; set; }

        /// <summary>
        /// Week of the course start
        /// </summary>
        [Required]
        [Range(1, 52, ErrorMessage = "Weeks must be in range 1-52")]
        public int StartWeek { get; set; }

        /// <summary>
        /// Week of the course end.
        /// </summary>
        [Required]
        [Range(1, 52, ErrorMessage = "Weeks must be in range 1-52")]
        public int EndWeek { get; set; }

        /// <summary>
        /// Course progression speed.
        /// </summary>
        [Required]
        [Range(1,100)]
        public int ProgressionSpeed { get; set; }

        public string Term { 
            get 
            {
                string term = "VT";
                if (Period > 3) term = "HT";
                else if (Period > 2) term = "SOM";
                return term + Year.ToString().Substring(2, 2);
            }
        }
    }
}